﻿/// <reference path="../scripts/jquery-1.11.2.min.js" />
/// <reference path="../scripts/bootstrap.min.js" />

if (typeof ($) != "undefined" && $) {
    $(document).ready(onReady);
}

function onReady() {
    $(".nav-title").html($.query.get("ctn"));
    $.ajax({
        type: "get",
        url: "api/common.ashx?ac=carlist&id=" + $.query.get("ct") + "&k=" + Math.random(),
        beforeSend: function () {
            $('#loadingToast').show();
        },
        error: function () {
            showToast("数据加载失败");
        },
        success: function (data) {
            if (data != null && data != '') {
                var list = eval("(" + data + ")");
                var htm = '';
                for (var i = 0; i < list.length; i++) {
                    var l = list[i];
                    htm += '<div class="sort_letter"><h3>' + l.ct + '</h3></div><ul class="list-infor01">';
                    var ctlist = l.list;
                    for (var m = 0; m < ctlist.length; m++) {
                        var ct = ctlist[m];
                        htm += '<li class="js-mall659"><a onclick="upCarType(' + ct.id + ',\'' + ct.name + '\')"><span class="caption">' + ct.name + '</span></a></li>';
                    }
                    htm += "</ul>";
                }
                $("#list").html(htm);
            }
        },
        complete: function () {
            $('#loadingToast').hide();
        }
    });
}

function upCarType(id, name) {
    if ($.query.get("cid") != '') {
        window.location.href = $.query.get("url") + '?cid=' + $.query.get("cid") + '&ctid=' + id + '&ct=' + encodeURIComponent(name);
    }
    else {
        window.location.href = $.query.get("url") + '?ctid=' + id + '&ct=' + encodeURIComponent(name);
    }

}

function goBack() {
    if ($.query.get("cid") != '') {
        window.location.href = 'cartype' + $.query.get("t") + '.html?url=' + $.query.get("url") + '&cid=' + $.query.get("cid");
    }
    else {
        window.location.href = 'cartype' + $.query.get("t") + '.html?url=' + $.query.get("url");
    }
}